var websocket=null;
websocket=new WebSocket("ws://localhost:8080/ws")

websocket.onerror=function () {
    appendMessage("error")
}
websocket.onopen=function (ev) {
    appendMessage("open")
}

websocket.onmessage=function (event) {
    appendMessage(event.data)
}
websocket.onclose=function (ev) {
    appendMessage("close")
}

window.onbeforeunload=function (ev) {
    websocket.close()
}
function appendMessage(message) {
    var context=$("#content").html()+"<br/>"+message;
    $("#content").html(context)
}
function closeWebSocket() {
    websocket.close()
}
function sendMessage() {
    var message=$("#message").val()
    websocket.send(message)
}